package ytmc.converter;

import java.io.*;
import java.util.Arrays;
import java.util.List;
import ytmc.FileSize;
import ytmc.FileUtils;
import ytmc.setup.*;


/**
 *
 * @author Kicok
 */
public class ConversionTask
{
    private File inputFile;
    private File outputFile;
    private ConversionType type;
    private ConversionStatus status;

    private VideoFormat videoFormat;
    private VideoResolution videoResolution;
    private int videoFrameRate;
    private AudioFormat audioFormat;
    private AudioQuality audioQuality;

    private FileSize inputFileSize;
    private int progress;
    private int remainingTime;


    public ConversionTask( String inputFilePath, String outputFilePath )
    {
        this( new File( inputFilePath ), new File( outputFilePath ) );
    }

    public ConversionTask( File inputFile, File outputFile )
    {
        this.inputFile = inputFile;
        this.outputFile = outputFile;
        this.type = getConversionTypeByExtension( FileUtils.getExtension( outputFile ) );
        this.status = ConversionStatus.NOT_STARTED;
        this.progress = -1;
        this.remainingTime = -1;

        this.inputFileSize = new FileSize( inputFile.length() );
    }

    private ConversionType getConversionTypeByExtension( String extension )
    {
        List<String> audioExtensions = Arrays.asList( AudioFormat.friendlyNames() );
        if( audioExtensions.contains( extension ) )
        {
            return ConversionType.AUDIO;
        }
        else
        {
            return ConversionType.VIDEO;
        }
    }


    public File getInputFile()
    {
        return inputFile;
    }

    public File getOutputFile()
    {
        return outputFile;
    }

    public ConversionType getType()
    {
        return type;
    }

    public ConversionStatus getStatus()
    {
        return status;
    }

    public void setStatus( ConversionStatus status )
    {
        this.status = status;

        switch( status )
        {
            case FAILED:
            case NOT_STARTED: setProgress( 0 ); break;
            case FINISHED: setProgress( 100 ); break;
        }
    }


    public VideoFormat getVideoFormat()
    {
        return videoFormat;
    }

    public void setVideoFormat( VideoFormat videoFormat )
    {
        this.videoFormat = videoFormat;
    }

    public VideoResolution getVideoResolution()
    {
        return videoResolution;
    }

    public void setVideoResolution( VideoResolution videoResolution )
    {
        this.videoResolution = videoResolution;
    }

    public int getVideoFrameRate()
    {
        return videoFrameRate;
    }

    public void setVideoFrameRate( int videoFrameRate )
    {
        this.videoFrameRate = videoFrameRate;
    }

    public AudioFormat getAudioFormat()
    {
        return audioFormat;
    }

    public void setAudioFormat( AudioFormat audioFormat )
    {
        this.audioFormat = audioFormat;
    }

    public AudioQuality getAudioQuality()
    {
        return audioQuality;
    }

    public void setAudioQuality( AudioQuality audioQuality )
    {
        this.audioQuality = audioQuality;
    }


    public FileSize getInputFileSize()
    {
        return inputFileSize;
    }

    public int getProgress()
    {
        return progress;
    }

    public void setProgress( int progress )
    {
        this.progress = progress;
    }

    public int getRemainingTime()
    {
        return remainingTime;
    }

    public void setRemainingTime( int remainingTime )
    {
        this.remainingTime = remainingTime;
    }
}